Home:ALL Converter>How to set the default PostgreSQL schema in Play?

How to set the default PostgreSQL schema in Play?

Ask Time:2013-04-10T20:52:15         Author:Ozgur Dogus

Json Formatter

We are using Play Framework 2.1 in our web application. We want to explicitly set the database schema (not public schema) in our PostgreSQL database that's the application's database. How can I set it ?

Author:Ozgur Dogus,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/15926383/how-to-set-the-default-postgresql-schema-in-play
a_horse_with_no_name :

If your tables are all located outside of the public schema, the best thing to do, is to change the search_path for your application user:\n\nalter user your_appuser set search_path = 'schema1';\n\n\nIf you have multiple schemas, you can add all of them:\n\nalter user your_appuser set search_path = 'schema1,schema2,public';\n\n\nDon't forget to commit this statement. The change will only have affect after the user logs in the next time. Existing connections will not be affected.",
2013-04-10T16:27:30
Wayan Wiprayoga :

As far as I know, from what I have tried before. You should define your schema name for each Model you want to. It should be like this:\n\nimport play.db.ebean.Model;\nimport javax.persistence.Entity;\nimport javax.persistence.Table;\n\n@Entity\n@Table(schema = \"schema2\")\npublic class TableOnSchema2 extends Model {\n ...\n}\n\n\nMaybe this solution would make an additional effort to define each Model with schema name. Because, I don't know whether there is configuration value can be set for specifying default database scheme for the application. But it works for me!\n\nHope this would help you.. :)",
2013-04-10T16:09:53
yy